package com.probiz.estoresa.catalog.web.action;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.catalog.service.ProductCategoryManager;
import com.probiz.estore.common.model.catalog.ProductCategory;
import com.probiz.estore.core.controller.GenericStoreAdminController;

public class ProductCategorySelectorController extends	GenericStoreAdminController<ProductCategory> {
	private ProductCategoryManager productCategoryManager = null;


	public void setProductCategoryManager(
			ProductCategoryManager productCategoryManager) {
		this.productCategoryManager = productCategoryManager;
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(ProductCategory entity) {
		return entity.getProductCategoryName();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.BaseController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = productCategoryManager;
	}

	

	@Override
	protected void preSave(HttpServletRequest request, ProductCategory entity,	BindException errors) {
		
	}

	
	public ModelAndView defaultAction(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("catalog/productCategorySelector");
		ProductCategory treeRoot = productCategoryManager.getById(1);
		Set<ProductCategory> categorySet = treeRoot.getChildren();
		List<ProductCategory> categoryList = new ArrayList<ProductCategory>();
		categoryList.addAll(categorySet);
		mv.addObject("categoryList", categoryList);
		mv.addObject("treeRoot", treeRoot);
		return mv;
	}
	
	
	
}
